/** CODE EVAL::Moderate [Longest Line]
 *	Write a program to read a multiple line text file and write 
 *	the 'N' longest lines to stdout. Where the file to be read 
 *	is specified on the command line.
 *
 *	Solution by Michael Pio Arroyo
 */

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdlib.h>

int main(int argc, char** argv) {
	std::ifstream file;
	std::string line;
	std::vector<std::string> linelist;
	file.open(argv[1]);

	// get the 'N' number of longest lines to find
	getline(file, line);
	int N = atoi(line.c_str());

	// create vector list of strings
	while(getline(file, line)) {
		linelist.push_back(line);
		size_t ls = linelist.size();
		if(ls > 1) {
			for(int i=ls-1; i>0; --i) {
				if(linelist.at(i).size() > linelist.at(i-1).size()) {
					std::string t = linelist.at(i);
					linelist.at(i) = linelist.at(i-1);
					linelist.at(i-1) = t;
				}
			}
		}
	}

	for(int i=0; i<N; ++i) {
		std::cout << linelist.at(i) << '\n';
	}

	file.close();
	return 0;
}